home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ARM / ARCH-RPC / IO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  187 lines

  1. /*
  2.  * linux/include/asm-arm/arch-rpc/io.h
  3.  *
  4.  * Copyright (C) 1997 Russell King
  5.  *
  6.  * Modifications:
  7.  *  06-Dec-1997    RMK    Created.
  8.  */
  9. #ifndef __ASM_ARM_ARCH_IO_H
  10. #define __ASM_ARM_ARCH_IO_H
  11.  
  12. /*
  13.  * This architecture does not require any delayed IO, and
  14.  * has the constant-optimised IO
  15.  */
  16. #undef    ARCH_IO_DELAY
  17.  
  18. /*
  19.  * We use two different types of addressing - PC style addresses, and ARM
  20.  * addresses.  PC style accesses the PC hardware with the normal PC IO
  21.  * addresses, eg 0x3f8 for serial#1.  ARM addresses are 0x80000000+
  22.  * and are translated to the start of IO.  Note that all addresses are
  23.  * shifted left!
  24.  */
  25. #define __PORT_PCIO(x)    (!((x) & 0x80000000))
  26.  
  27. /*
  28.  * Dynamic IO functions - let the compiler
  29.  * optimize the expressions
  30.  */
  31. #define DECLARE_DYN_OUT(fnsuffix,instr)                        \
  32. extern __inline__ void __out##fnsuffix (unsigned int value, unsigned int port)    \
  33. {                                        \
  34.     unsigned long temp;                            \
  35.     __asm__ __volatile__(                            \
  36.     "tst    %2, #0x80000000\n\t"                        \
  37.     "mov    %0, %4\n\t"                            \
  38.     "addeq    %0, %0, %3\n\t"                            \
  39.     "str" ##instr## "    %1, [%0, %2, lsl #2]    @ out"###fnsuffix    \
  40.     : "=&r" (temp)                                \
  41.     : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)    \
  42.     : "cc");                                \
  43. }
  44.  
  45. #define DECLARE_DYN_IN(sz,fnsuffix,instr)                    \
  46. extern __inline__ unsigned sz __in##fnsuffix (unsigned int port)        \
  47. {                                        \
  48.     unsigned long temp, value;                        \
  49.     __asm__ __volatile__(                            \
  50.     "tst    %2, #0x80000000\n\t"                        \
  51.     "mov    %0, %4\n\t"                            \
  52.     "addeq    %0, %0, %3\n\t"                            \
  53.     "ldr" ##instr## "    %1, [%0, %2, lsl #2]    @ in"###fnsuffix    \
  54.     : "=&r" (temp), "=r" (value)                        \
  55.     : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)        \
  56.     : "cc");                                \
  57.     return (unsigned sz)value;                        \
  58. }
  59.  
  60. extern __inline__ unsigned int __ioaddr (unsigned int port)            \
  61. {                                        \
  62.     if (__PORT_PCIO(port))                            \
  63.         return (unsigned int)(PCIO_BASE + (port << 2));            \
  64.     else                                    \
  65.         return (unsigned int)(IO_BASE + (port << 2));            \
  66. }
  67.  
  68. #define DECLARE_IO(sz,fnsuffix,instr)    \
  69.     DECLARE_DYN_OUT(fnsuffix,instr)    \
  70.     DECLARE_DYN_IN(sz,fnsuffix,instr)
  71.  
  72. DECLARE_IO(char,b,"b")
  73. DECLARE_IO(short,w,"")
  74. DECLARE_IO(long,l,"")
  75.  
  76. #undef DECLARE_IO
  77. #undef DECLARE_DYN_OUT
  78. #undef DECLARE_DYN_IN
  79.  
  80. /*
  81.  * Constant address IO functions
  82.  *
  83.  * These have to be macros for the 'J' constraint to work -
  84.  * +/-4096 immediate operand.
  85.  */
  86. #define __outbc(value,port)                            \
  87. ({                                        \
  88.     if (__PORT_PCIO((port)))                        \
  89.         __asm__ __volatile__(                        \
  90.         "strb    %0, [%1, %2]    @ outbc"                \
  91.         : : "r" (value), "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  92.     else                                    \
  93.         __asm__ __volatile__(                        \
  94.         "strb    %0, [%1, %2]    @ outbc"                \
  95.         : : "r" (value), "r" (IO_BASE), "r" ((port) << 2));        \
  96. })
  97.  
  98. #define __inbc(port)                                \
  99. ({                                        \
  100.     unsigned char result;                            \
  101.     if (__PORT_PCIO((port)))                        \
  102.         __asm__ __volatile__(                        \
  103.         "ldrb    %0, [%1, %2]    @ inbc"                    \
  104.         : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  105.     else                                    \
  106.         __asm__ __volatile__(                        \
  107.         "ldrb    %0, [%1, %2]    @ inbc"                    \
  108.         : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2));        \
  109.     result;                                    \
  110. })
  111.  
  112. #define __outwc(value,port)                            \
  113. ({                                        \
  114.     unsigned long v = value;                        \
  115.     if (__PORT_PCIO((port)))                        \
  116.         __asm__ __volatile__(                        \
  117.         "str    %0, [%1, %2]    @ outwc"                \
  118.         : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" ((port) << 2));    \
  119.     else                                    \
  120.         __asm__ __volatile__(                        \
  121.         "str    %0, [%1, %2]    @ outwc"                \
  122.         : : "r" (v|v<<16), "r" (IO_BASE), "r" ((port) << 2));        \
  123. })
  124.  
  125. #define __inwc(port)                                \
  126. ({                                        \
  127.     unsigned short result;                            \
  128.     if (__PORT_PCIO((port)))                        \
  129.         __asm__ __volatile__(                        \
  130.         "ldr    %0, [%1, %2]    @ inwc"                    \
  131.         : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  132.     else                                    \
  133.         __asm__ __volatile__(                        \
  134.         "ldr    %0, [%1, %2]    @ inwc"                    \
  135.         : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2));        \
  136.     result & 0xffff;                            \
  137. })
  138.  
  139. #define __outlc(value,port)                            \
  140. ({                                        \
  141.     unsigned long v = value;                        \
  142.     if (__PORT_PCIO((port)))                        \
  143.         __asm__ __volatile__(                        \
  144.         "str    %0, [%1, %2]    @ outlc"                \
  145.         : : "r" (v), "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  146.     else                                    \
  147.         __asm__ __volatile__(                        \
  148.         "str    %0, [%1, %2]    @ outlc"                \
  149.         : : "r" (v), "r" (IO_BASE), "r" ((port) << 2));            \
  150. })
  151.  
  152. #define __inlc(port)                                \
  153. ({                                        \
  154.     unsigned long result;                            \
  155.     if (__PORT_PCIO((port)))                        \
  156.         __asm__ __volatile__(                        \
  157.         "ldr    %0, [%1, %2]    @ inlc"                    \
  158.         : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  159.     else                                    \
  160.         __asm__ __volatile__(                        \
  161.         "ldr    %0, [%1, %2]    @ inlc"                    \
  162.         : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2));        \
  163.     result;                                    \
  164. })
  165.  
  166. #define __ioaddrc(port)                                \
  167.     (__PORT_PCIO((port)) ? PCIO_BASE + ((port) << 2) : IO_BASE + ((port) << 2))
  168.  
  169. /*
  170.  * Translated address IO functions
  171.  *
  172.  * IO address has already been translated to a virtual address
  173.  */
  174. #define outb_t(v,p)                                \
  175.     (*(volatile unsigned char *)(p) = (v))
  176.  
  177. #define inb_t(p)                                \
  178.     (*(volatile unsigned char *)(p))
  179.  
  180. #define outl_t(v,p)                                \
  181.     (*(volatile unsigned long *)(p) = (v))
  182.  
  183. #define inl_t(p)                                \
  184.     (*(volatile unsigned long *)(p))
  185.  
  186. #endif
  187.